package com.imaker.utils;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

public class CacheUtils {

	/**
	 * 添加缓存
	 * @param key
	 * @param cacheName
	 * @param value
	 */
	public static void put(String cName,String key,Object value){
		 Cache cache = CacheManager.getInstance().getCache(cName);
         cache.put(new Element(key, value));
         cache.flush();
	}
	
	/**
	 * 获得缓存
	 * @param cName
	 * @param key
	 * @return
	 */
	public static Object get(String cName,String key){
		Cache cache = CacheManager.getInstance().getCache(cName);
		Element elem = cache.get(key);
		return elem == null ? null:elem.getValue();
	}
}
